package br.com.exceptiongroup.chatexception.persistence;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;

import br.com.exceptiongroup.chatexception.model.BaseBean;

public abstract class AbstractMongoDAO<T extends BaseBean> implements GenericDAO<T> {
	
	@Autowired
	protected MongoTemplate mongoTemplate;
	
	private Class<T> clazz;
	
	public AbstractMongoDAO(Class<T> clazz) {
		this.clazz = clazz;
	}
	
	@Override
	public void add(T obj) {
		mongoTemplate.insert(obj);
	}
	
	@Override
	public List<T> getAll() {
		return mongoTemplate.findAll(clazz);
	}
	
	@Override
	public void remove(T entity) {
		mongoTemplate.remove(entity);
	}
}
